package com.leen.news.feign.factory;

import com.leen.common.vo.ResultEnum;
import com.leen.common.vo.ResultVO;
import com.leen.exam.entity.News;
import com.leen.news.feign.INewsFeignClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

/**
 * feign集成histrx的断熔服务类说明
 *
 * @author admin
 * @date 2021-05-18
 */
@Log4j2
@Component
public class NewsFeignClientFallbackFactory implements FallbackFactory<INewsFeignClient> {

    @Override
    public INewsFeignClient create(Throwable throwable) {
         log.error(throwable);
        return new NewsFeignClientImpl();
    }


    /**
     * 内部类 (服务降级的方法)
     */
    class  NewsFeignClientImpl implements INewsFeignClient{

        @Override
        public ResultVO getNewsData() {
            System.out.println("服务降级 ");

            return ResultVO.failed(ResultEnum.FEIGN_FALLBACK);
        }

        @Override
        public int addNewsTag(News news) {
            System.out.println("NewsFeignClientImpl服务降级 ");
            return 0;
        }
    }


}
